package com.sanrenzu.chunbo.ui.vertical.gengduo;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.adapter.GengDuoListView;
import com.sanrenzu.chunbo.bean.zxb.ShuiGuoChildBean;
import com.sanrenzu.chunbo.ui.fenlei.gengduo.GengDuoContractF;
import com.sanrenzu.chunbo.ui.fenlei.gengduo.GengDuoFragment;
import com.sanrenzu.chunbo.widget.MyListView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GengDuoActivity extends AppCompatActivity implements GengDuoContract.View {

    //listview
    @BindView(R.id.gengduo_listview_main)
    MyListView gengduoListviewMain;

    private GengDuoContract.Persenter persenter;
    private GengDuoListView gengDuoListViewAdapter;

    private GengDuoContractF.Persenter persenterF;
    private Context context = this;

    private String dia="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_geng_duo);
        ButterKnife.bind(this);

        persenter = new GengDuoPersenter(this);
        persenter.onGerVerticalShuiGuo();
    }

    @Override
    public void onGetVerticalShuiGuoChildBean(List<ShuiGuoChildBean> shuiGuoChildBeen) {
        gengDuoListViewAdapter = new GengDuoListView(context, shuiGuoChildBeen);
        gengduoListviewMain.setAdapter(gengDuoListViewAdapter);
        gengduoListviewMain.setSelection(0);
        gengduoListviewMain.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               switch (position){
                       case 0:
                           dia = "1";
                           break;
                       case 1:
                           dia = "2";
                           break;
                       case 2:
                           dia = "4";
                           break;
                       case 3:
                           dia = "9";
                           break;
                       case 4:
                           dia = "10";
                           break;
                       case 5:
                           dia = "11";
                           break;
                       case 6:
                           dia = "12";
                           break;

               }
                GengDuoFragment fragment =new GengDuoFragment().newInstance(dia);
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.gengduo_fragmelayout,fragment);
                transaction.commit();
            }
        });
    }
}
